import request from '@/utils/request'
import type {
  CommentSaveParam,
  CommentTreeParam,
  LoadMoreChildrenParam,
  CommentLikeParam,
  CommentPageResponse,
  CommentStats,
  Comment,
} from '@/types/comment'

// 保存评论
export const commentSave = async (params: CommentSaveParam): Promise<unknown> => {
  return request({
    url: '/portal/comment/save',
    method: 'post',
    data: params,
  })
}

// 获取评论树
export const getCommentTree = async (params: CommentTreeParam): Promise<CommentPageResponse> => {
  return request({
    url: '/portal/comment/tree',
    method: 'post',
    data: params,
  })
}

// 加载更多子评论
export const loadMoreChildren = async (params: LoadMoreChildrenParam): Promise<Comment[]> => {
  return request({
    url: '/portal/comment/load-more',
    method: 'post',
    data: params,
  })
}

// 点赞/取消点赞评论
export const likeComment = async (params: CommentLikeParam): Promise<unknown> => {
  return request({
    url: '/portal/comment/like',
    method: 'post',
    data: params,
  })
}

// 获取评论统计信息
export const getCommentStats = async (blogId: string): Promise<CommentStats> => {
  return request({
    url: `/portal/comment/stats/${blogId}`,
    method: 'get',
  })
}
